<?php

/**
 * @file IndexHandler.inc.php
 *
 * Copyright (c) 2003-2012 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class IndexHandler
 * @ingroup pages_index
 *
 * @brief Handle site index requests.
 */

// $Id$


import('classes.handler.Handler');

class IndexHandler extends Handler {
	/**
	 * Constructor
	 **/
	function IndexHandler() {
		parent::Handler();
	}

	/**
	 * If no journal is selected, display list of journals.
	 * Otherwise, display the index page for the selected journal.
	 * @param $args array
	 * @param $request Request
	 */
	function index($args, &$request) {

		$gcNam = null;
		if ($args[0] != null)
			$gcNam =  $args[0];

		$this->validate();
		$this->setupTemplate();


		$router =& $request->getRouter();
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);
		$templateMgr->assign('helpTopicId', 'user.home');
		$templateMgr->assign('gcNam', $gcNam);
		$journal =& $router->getContext($request);



		if ($journal) {
			// Assign header and content for home page
			$templateMgr->assign_by_ref('journal', $journal);
			$templateMgr->assign('displayPageHeaderTitle', $journal->getLocalizedPageHeaderTitle(true));
			$templateMgr->assign('displayPageHeaderLogo', $journal->getLocalizedPageHeaderLogo(true));
			$templateMgr->assign('displayPageHeaderTitleAltText', $journal->getLocalizedSetting('homeHeaderTitleImageAltText'));
			$templateMgr->assign('displayPageHeaderLogoAltText', $journal->getLocalizedSetting('homeHeaderLogoImageAltText'));
			$templateMgr->assign('additionalHomeContent', $journal->getLocalizedSetting('additionalHomeContent'));
			$templateMgr->assign('homepageImage', $journal->getLocalizedSetting('homepageImage'));
			$templateMgr->assign('homepageImageAltText', $journal->getLocalizedSetting('homepageImageAltText'));
			$templateMgr->assign('journalDescription', $journal->getLocalizedSetting('description'));
			$templateMgr->assign('CN_SecDetail', "CN_MUAHANGCNO");  //default


			$displayCurrentIssue = $journal->getSetting('displayCurrentIssue');
			$issueDao =& DAORegistry::getDAO('IssueDAO');
			$issue =& $issueDao->getCurrentIssue($journal->getId(), true);
			if ($displayCurrentIssue && isset($issue)) {
				import('pages.issue.IssueHandler');
				// The current issue TOC/cover page should be displayed below the custom home page.
				IssueHandler::setupIssueTemplate($issue);
			}

			// Display creative commons logo/licence if enabled
			$templateMgr->assign('displayCreativeCommons', $journal->getSetting('includeCreativeCommons'));

			$enableAnnouncements = $journal->getSetting('enableAnnouncements');
			if ($enableAnnouncements) {
				$enableAnnouncementsHomepage = $journal->getSetting('enableAnnouncementsHomepage');
				if ($enableAnnouncementsHomepage) {
					$numAnnouncementsHomepage = $journal->getSetting('numAnnouncementsHomepage');
					$announcementDao =& DAORegistry::getDAO('AnnouncementDAO');
					$announcements =& $announcementDao->getNumAnnouncementsNotExpiredByAssocId(ASSOC_TYPE_JOURNAL, $journal->getId(), $numAnnouncementsHomepage);
					$templateMgr->assign('announcements', $announcements);
					$templateMgr->assign('enableAnnouncementsHomepage', $enableAnnouncementsHomepage);
				}
			}
			$templateMgr->display('index/journal.tpl');
		} else {
			$site =& Request::getSite();

			if ($site->getRedirect() && ($journal = $journalDao->getJournal($site->getRedirect())) != null) {
				$request->redirect($journal->getPath());
			}

			$templateMgr->assign('intro', $site->getLocalizedIntro());
			$templateMgr->assign('journalFilesPath', $request->getBaseUrl() . '/' . Config::getVar('files', 'public_files_dir') . '/journals/');
			$journals =& $journalDao->getEnabledJournals();

			$templateMgr->setCacheability(CACHEABILITY_PUBLIC);
			// lan dau tien chtr chay vao day
			$templateMgr->display('index/site.tpl');
		}
	}

	//newv
	// remove function CN_TMTG($args, &$request) {
	//newv end
	function SS_TMTG($args, &$request) {
		$gcNam = $args;
		$router =& $request->getRouter();
		
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);
		$templateMgr->assign('helpTopicId', 'user.home');

		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();

		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "SoSach");
		$templateMgr->assign('SS_SecDetail', "SS_TMTG");
		$templateMgr->assign('Sec_Title', "S&#7893; Tiền mặt - Tiền gửi" );
		$templateMgr->assign('SS_Title', "Sổ Tiền mặt - Tiền gửi" );
		$templateMgr->assign('sectionOptions', $dmtkOptions );
		$templateMgr->assign_by_ref('journal', $journal);

		$date1 = mktime(0, 0, 0, date("m"), 1, date("y"));
        $date2 = mktime(0, 0, 0, date("m")+1, 0,date("y"));
		$ngay1 = date ( 'Y-m-d', $date1 );
		$ngay2 = date ( 'Y-m-d', $date2 );
		$templateMgr->assign('ngay1', $ngay1);
		$templateMgr->assign('ngay2', $ngay2);

		$dmtkDao =& DAORegistry::getDAO('DMTKDAO');
		$dstk =& $dmtkDao->getDSMATENTK("11");
		$templateMgr->assign('tktienas', $dstk);
		$dmntDao =& DAORegistry::getDAO('DMNTDAO');
		$dsmant =& $dmntDao->getDSMANT_MA();
		$templateMgr->assign('dmntf', $dsmant );
		$templateMgr->assign('LoaiTien', "VND" );



		$templateMgr->assign(newurl , Request::url(null, 'acctSS', 'SS_TMTG'));
		$templateMgr->addJavaScript("classes/acct/js/Baocao.js");
		$templateMgr->display('acctSS/sstmtg.tpl');

	}


	function CN_BANHANGCNO($args, &$request) {
		$templateMgr =& TemplateManager::getManager();

		$now = time();
		$Nam = Request::getUserVar("Nam");
		if ($Nam)
			$date1 = mktime(0, 0, 0, 1, 1, $Nam);
		else
			$date1 = time();  
		$templateMgr->assign('ngay', $date1);

		$LoaiTien  = Request::getUserVar("LoaiTien");
		if (!$LoaiTien)
			$LoaiTien = "VND";
		$templateMgr->assign('LoaiTien', $LoaiTien);
		
		$ChiTiet  = Request::getUserVar("ChiTiet");
		if (!$ChiTiet)
			$ChiTiet = "HDA";
		$templateMgr->assign('ChiTiet', $ChiTiet);


		$router =& $request->getRouter();
		
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);
		$templateMgr->assign('helpTopicId', 'user.home');

		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();

		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "CapNhat");
		$templateMgr->assign('CN_SecDetail', "CN_BANHANGCNO");
		$templateMgr->assign('CN_Title', "B&#225;n h&#224;ng v&#224; C&#244;ng n&#7907; pha&#7881; thu " );

		$templateMgr->assign_by_ref('journal', $journal);
		$newurl = Request::url(null, 'index', 'CN_BANHANGCNO');
		$templateMgr->assign(newurl , Request::url(null, 'acctCN', 'CN_BANHANGCNO'));



//		$gcNam = $args;
//		$router =& $request->getRouter();
//		$templateMgr =& TemplateManager::getManager();
//		$journalDao =& DAORegistry::getDAO('JournalDAO');
//		$journalPath = $router->getRequestedContextPath($request);
//		$templateMgr->assign('helpTopicId', 'user.home');
//		
//		$user =& Request::getUser();
//		$xma_dvcs = $user->getPath();
//
//		$templateMgr->assign('gcNam', $gcNam);
//		$templateMgr->assign('PhanHe', "CapNhat");
//		$templateMgr->assign('CN_SecDetail', "CN_BANHANGCNO");
//		$templateMgr->assign('CN_Title', "B&#225;n h&#224;ng v&#224; C&#244;ng n&#7907; pha&#7881; thu " );
//		$templateMgr->assign_by_ref('journal', $journal);
//		$templateMgr->assign(newurl , Request::url(null, 'acctCN', 'CN_BANHANGCNO'));
//		//echo "Tien mat tien gui";
		$templateMgr->display('acctCN/index.tpl');
		return;
	}

	function CN_MUAHANGCNO($args, &$request) {
		$gcNam = $args;
		$router =& $request->getRouter();
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);
		$templateMgr->assign('helpTopicId', 'user.home');
		
		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();

		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "CapNhat");
		$templateMgr->assign('CN_SecDetail', "CN_MUAHANGCNO");
		$templateMgr->assign('CN_Title', "Mua h&#224;ng & C&#244;ng n&#7907; ph&#7843;i tr&#7843;" );
		$templateMgr->assign_by_ref('journal', $journal);

		$templateMgr->assign(newurl , Request::url(null, 'acctCN', 'CN_MUAHANGCNO'));
		//echo "Tien mat tien gui";
		$templateMgr->display('acctCN/index.tpl');

	}

	function SS_TK($args, &$request) {
		$dmtkDao =& DAORegistry::getDAO('DMTKDAO');
		$dmtkOptions =& $dmtkDao->getDMTK(null, false, true);

		$gcNam = $args;
		$router =& $request->getRouter();
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);
		$templateMgr->assign('helpTopicId', 'user.home');
		

		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();


		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "SoSach");
		$templateMgr->assign('SS_SecDetail', "SS_TK");
		$templateMgr->assign('Sec_Title', "S&#7893; T&#224;i kho&#7843;n" );
		$templateMgr->assign('sectionOptions', $dmtkOptions );
		$templateMgr->assign_by_ref('journal', $journal);

		$templateMgr->assign(newurl , Request::url(null, 'acctSS', 'SS_TK'));
		$templateMgr->display('acctSS/index.tpl');

	}



	function KT_DANHMUC($args, &$request) {
		$router =& $request->getRouter();
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);

		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();

		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "CapNhat");
		$templateMgr->assign('KT_SecDetail', "KT_DANHMUC");

		$templateMgr->assign('Sec_Title', "Danh m&#7909;c" );
		$templateMgr->assign_by_ref('journal', $journal);

		$newurl = Request::url(null, 'acctKT', 'KT_DANHMUC');
		$templateMgr->assign('newurl' , $newurl );
		$templateMgr->display('acctKT/ktDM.tpl');
	

	}

	function KT_SDTT($args, &$request) {
		$gcNam = $args;
		$router =& $request->getRouter();
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);

		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();

		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "KhoiTao");
		$templateMgr->assign('KT_SecDetail', "KT_SDTT");

		$templateMgr->assign('Sec_Title', "Kh&#7903;i t&#7841;o S&#7889; d&#432; Ti&#7873;n t&#7879;" );

		$templateMgr->assign_by_ref('journal', $journal);
		$newurl = Request::url(null, 'acctKT', 'KT_SDTT');
	
		$templateMgr->assign('newurl' , $newurl );

		$templateMgr->display('acctKT/ktSDTT.tpl');

	}


function KT_SDTK($args, &$request) {
		$gcNam = $args;
		$router =& $request->getRouter();
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);

		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();

		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "KhoiTao");
		$templateMgr->assign('KT_SecDetail', "KT_SDTK");

		$templateMgr->assign('Sec_Title', "Kh&#7903;i t&#7841;o S&#7889; d&#432; Tài khoản" );

		$templateMgr->assign_by_ref('journal', $journal);
		$newurl = Request::url(null, 'acctKT', 'KT_SDTK');
	
		$templateMgr->assign('newurl' , $newurl );

		$templateMgr->display('acctKT/ktSDTK.tpl');

	}

	function KT_SODU($args, &$request) {
		$gcNam = $args;
		$router =& $request->getRouter();
		$templateMgr =& TemplateManager::getManager();
		$journalDao =& DAORegistry::getDAO('JournalDAO');
		$journalPath = $router->getRequestedContextPath($request);
		$templateMgr->assign('helpTopicId', 'user.home');

		$user =& Request::getUser();
		$xma_dvcs = $user->getPath();

		$templateMgr->assign('gcNam', $gcNam);
		$templateMgr->assign('PhanHe', "CapNhat");
		$templateMgr->assign('CN_SecDetail', "CN_TMTG");
		$templateMgr->assign('CN_Title', "Ti&#7873;n m&#7863;t - Ti&#7873;n g&#7917;i" );
		$templateMgr->assign_by_ref('journal', $journal);
		$newurl = Request::url(null, 'index', 'CN_TMTG');
		$templateMgr->assign(newurl , Request::url(null, 'acctCN', 'CN_TMTG'));
		//echo "Tien mat tien gui";
		$templateMgr->display('acctCN/index.tpl');

	}



}

?>
